package com.itshare.video.mapper;

import com.itshare.video.pojo.po.UserMessage;
import com.itshare.video.pojo.po.UserMessageExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface UserMessageMapper {
    long countByExample(UserMessageExample example);

    int deleteByExample(UserMessageExample example);

    @Delete({
        "delete from t_user_message",
        "where message_id = #{messageId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer messageId);

    @Insert({
        "insert into t_user_message (from_user_id, from_user_name, ",
        "to_user_name, to_user_id, ",
        "to_user_message, delete_status, ",
        "has_read, message_type, ",
        "create_time, update_time, ",
        "videoId, feedback_title, ",
        "image, from_user_phone)",
        "values (#{fromUserId,jdbcType=INTEGER}, #{fromUserName,jdbcType=VARCHAR}, ",
        "#{toUserName,jdbcType=VARCHAR}, #{toUserId,jdbcType=INTEGER}, ",
        "#{toUserMessage,jdbcType=VARCHAR}, #{deleteStatus,jdbcType=INTEGER}, ",
        "#{hasRead,jdbcType=INTEGER}, #{messageType,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{videoid,jdbcType=INTEGER}, #{feedbackTitle,jdbcType=VARCHAR}, ",
        "#{image,jdbcType=VARCHAR}, #{fromUserPhone,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="messageId", before=false, resultType=Integer.class)
    int insert(UserMessage record);

    int insertSelective(UserMessage record);

    List<UserMessage> selectByExampleWithRowbounds(UserMessageExample example, RowBounds rowBounds);

    List<UserMessage> selectByExample(UserMessageExample example);

    @Select({
        "select",
        "message_id, from_user_id, from_user_name, to_user_name, to_user_id, to_user_message, ",
        "delete_status, has_read, message_type, create_time, update_time, videoId, feedback_title, ",
        "image, from_user_phone",
        "from t_user_message",
        "where message_id = #{messageId,jdbcType=INTEGER}"
    })
    @ResultMap("com.itshare.video.mapper.UserMessageMapper.BaseResultMap")
    UserMessage selectByPrimaryKey(Integer messageId);

    int updateByExampleSelective(@Param("record") UserMessage record, @Param("example") UserMessageExample example);

    int updateByExample(@Param("record") UserMessage record, @Param("example") UserMessageExample example);

    int updateByPrimaryKeySelective(UserMessage record);

    @Update({
        "update t_user_message",
        "set from_user_id = #{fromUserId,jdbcType=INTEGER},",
          "from_user_name = #{fromUserName,jdbcType=VARCHAR},",
          "to_user_name = #{toUserName,jdbcType=VARCHAR},",
          "to_user_id = #{toUserId,jdbcType=INTEGER},",
          "to_user_message = #{toUserMessage,jdbcType=VARCHAR},",
          "delete_status = #{deleteStatus,jdbcType=INTEGER},",
          "has_read = #{hasRead,jdbcType=INTEGER},",
          "message_type = #{messageType,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "videoId = #{videoid,jdbcType=INTEGER},",
          "feedback_title = #{feedbackTitle,jdbcType=VARCHAR},",
          "image = #{image,jdbcType=VARCHAR},",
          "from_user_phone = #{fromUserPhone,jdbcType=VARCHAR}",
        "where message_id = #{messageId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(UserMessage record);
}